package com.choudou5.solr.web.handler.sys;

import com.choudou5.solr.framework.bean.UserSessionBean;
import com.choudou5.solr.framework.constants.ErrorResp;
import com.choudou5.solr.framework.util.PageJumpUtil;
import com.choudou5.solr.framework.util.UserUtil;
import com.choudou5.solr.web.handler.BaseHandler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Name：页面处理器
 * @Author：choudou5
 * @Date：2018-07-14
 */
public class PageHandler extends BaseHandler {

    /**
     * @param page 页面 （无后缀名）
     * @param req
     * @param resp
     */
    @Override
    public void execute(String page, HttpServletRequest req, HttpServletResponse resp) {
        logger.info("PageHandler page:{}", page);
        if(!"GET".equalsIgnoreCase(req.getMethod())){
            PageJumpUtil.errorOut(ErrorResp.Not_Method_Allowed, req, resp);
            return;
        }

        UserSessionBean userSessionBean = UserUtil.getUser();
        if(userSessionBean != null)
            req.setAttribute("userSessionBean", userSessionBean);
        PageJumpUtil.forward(page, req, resp);
    }

}
